﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using Indeco.G24.Entities;
using Indeco.G24.Data;

#endregion

namespace Indeco.G24.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="TinTucDanhMucProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class TinTucDanhMucProviderBaseCore : EntityProviderBase<Indeco.G24.Entities.TinTucDanhMuc, Indeco.G24.Entities.TinTucDanhMucKey>
	{		
		#region Get from Many To Many Relationship Functions
		#region GetByIDTinTucFromTinTucTieuDiem
		
		/// <summary>
		///		Gets tb_TinTucDanhMuc objects from the datasource by ID_TinTuc in the
		///		tb_TinTucTieuDiem table. Table tb_TinTucDanhMuc is related to table tb_TinTuc
		///		through the (M:N) relationship defined in the tb_TinTucTieuDiem table.
		/// </summary>
		/// <param name="iDTinTuc"></param>
		/// <returns>Returns a typed collection of TinTucDanhMuc objects.</returns>
		public TList<TinTucDanhMuc> GetByIDTinTucFromTinTucTieuDiem(System.Guid iDTinTuc)
		{
			int count = -1;
			return GetByIDTinTucFromTinTucTieuDiem(null,iDTinTuc, 0, int.MaxValue, out count);
			
		}
		
		/// <summary>
		///		Gets Indeco.G24.Entities.TinTucDanhMuc objects from the datasource by ID_TinTuc in the
		///		tb_TinTucTieuDiem table. Table tb_TinTucDanhMuc is related to table tb_TinTuc
		///		through the (M:N) relationship defined in the tb_TinTucTieuDiem table.
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="iDTinTuc"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of TinTucDanhMuc objects.</returns>
		public TList<TinTucDanhMuc> GetByIDTinTucFromTinTucTieuDiem(System.Guid iDTinTuc, int start, int pageLength)
		{
			int count = -1;
			return GetByIDTinTucFromTinTucTieuDiem(null, iDTinTuc, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets TinTucDanhMuc objects from the datasource by ID_TinTuc in the
		///		tb_TinTucTieuDiem table. Table tb_TinTucDanhMuc is related to table tb_TinTuc
		///		through the (M:N) relationship defined in the tb_TinTucTieuDiem table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDTinTuc"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of tb_TinTucDanhMuc objects.</returns>
		public TList<TinTucDanhMuc> GetByIDTinTucFromTinTucTieuDiem(TransactionManager transactionManager, System.Guid iDTinTuc)
		{
			int count = -1;
			return GetByIDTinTucFromTinTucTieuDiem(transactionManager, iDTinTuc, 0, int.MaxValue, out count);
		}
		
		
		/// <summary>
		///		Gets TinTucDanhMuc objects from the datasource by ID_TinTuc in the
		///		tb_TinTucTieuDiem table. Table tb_TinTucDanhMuc is related to table tb_TinTuc
		///		through the (M:N) relationship defined in the tb_TinTucTieuDiem table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDTinTuc"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of tb_TinTucDanhMuc objects.</returns>
		public TList<TinTucDanhMuc> GetByIDTinTucFromTinTucTieuDiem(TransactionManager transactionManager, System.Guid iDTinTuc,int start, int pageLength)
		{
			int count = -1;
			return GetByIDTinTucFromTinTucTieuDiem(transactionManager, iDTinTuc, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets TinTucDanhMuc objects from the datasource by ID_TinTuc in the
		///		tb_TinTucTieuDiem table. Table tb_TinTucDanhMuc is related to table tb_TinTuc
		///		through the (M:N) relationship defined in the tb_TinTucTieuDiem table.
		/// </summary>
		/// <param name="iDTinTuc"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of tb_TinTucDanhMuc objects.</returns>
		public TList<TinTucDanhMuc> GetByIDTinTucFromTinTucTieuDiem(System.Guid iDTinTuc,int start, int pageLength, out int count)
		{
			
			return GetByIDTinTucFromTinTucTieuDiem(null, iDTinTuc, start, pageLength, out count);
		}


		/// <summary>
		///		Gets tb_TinTucDanhMuc objects from the datasource by ID_TinTuc in the
		///		tb_TinTucTieuDiem table. Table tb_TinTucDanhMuc is related to table tb_TinTuc
		///		through the (M:N) relationship defined in the tb_TinTucTieuDiem table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <param name="iDTinTuc"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of TinTucDanhMuc objects.</returns>
		public abstract TList<TinTucDanhMuc> GetByIDTinTucFromTinTucTieuDiem(TransactionManager transactionManager,System.Guid iDTinTuc, int start, int pageLength, out int count);
		
		#endregion GetByIDTinTucFromTinTucTieuDiem
		
		#region GetByIDTinTucFromTinTucSuKien
		
		/// <summary>
		///		Gets tb_TinTucDanhMuc objects from the datasource by ID_TinTuc in the
		///		tb_TinTucSuKien table. Table tb_TinTucDanhMuc is related to table tb_TinTuc
		///		through the (M:N) relationship defined in the tb_TinTucSuKien table.
		/// </summary>
		/// <param name="iDTinTuc"></param>
		/// <returns>Returns a typed collection of TinTucDanhMuc objects.</returns>
		public TList<TinTucDanhMuc> GetByIDTinTucFromTinTucSuKien(System.Guid iDTinTuc)
		{
			int count = -1;
			return GetByIDTinTucFromTinTucSuKien(null,iDTinTuc, 0, int.MaxValue, out count);
			
		}
		
		/// <summary>
		///		Gets Indeco.G24.Entities.TinTucDanhMuc objects from the datasource by ID_TinTuc in the
		///		tb_TinTucSuKien table. Table tb_TinTucDanhMuc is related to table tb_TinTuc
		///		through the (M:N) relationship defined in the tb_TinTucSuKien table.
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="iDTinTuc"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of TinTucDanhMuc objects.</returns>
		public TList<TinTucDanhMuc> GetByIDTinTucFromTinTucSuKien(System.Guid iDTinTuc, int start, int pageLength)
		{
			int count = -1;
			return GetByIDTinTucFromTinTucSuKien(null, iDTinTuc, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets TinTucDanhMuc objects from the datasource by ID_TinTuc in the
		///		tb_TinTucSuKien table. Table tb_TinTucDanhMuc is related to table tb_TinTuc
		///		through the (M:N) relationship defined in the tb_TinTucSuKien table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDTinTuc"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of tb_TinTucDanhMuc objects.</returns>
		public TList<TinTucDanhMuc> GetByIDTinTucFromTinTucSuKien(TransactionManager transactionManager, System.Guid iDTinTuc)
		{
			int count = -1;
			return GetByIDTinTucFromTinTucSuKien(transactionManager, iDTinTuc, 0, int.MaxValue, out count);
		}
		
		
		/// <summary>
		///		Gets TinTucDanhMuc objects from the datasource by ID_TinTuc in the
		///		tb_TinTucSuKien table. Table tb_TinTucDanhMuc is related to table tb_TinTuc
		///		through the (M:N) relationship defined in the tb_TinTucSuKien table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDTinTuc"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of tb_TinTucDanhMuc objects.</returns>
		public TList<TinTucDanhMuc> GetByIDTinTucFromTinTucSuKien(TransactionManager transactionManager, System.Guid iDTinTuc,int start, int pageLength)
		{
			int count = -1;
			return GetByIDTinTucFromTinTucSuKien(transactionManager, iDTinTuc, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets TinTucDanhMuc objects from the datasource by ID_TinTuc in the
		///		tb_TinTucSuKien table. Table tb_TinTucDanhMuc is related to table tb_TinTuc
		///		through the (M:N) relationship defined in the tb_TinTucSuKien table.
		/// </summary>
		/// <param name="iDTinTuc"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of tb_TinTucDanhMuc objects.</returns>
		public TList<TinTucDanhMuc> GetByIDTinTucFromTinTucSuKien(System.Guid iDTinTuc,int start, int pageLength, out int count)
		{
			
			return GetByIDTinTucFromTinTucSuKien(null, iDTinTuc, start, pageLength, out count);
		}


		/// <summary>
		///		Gets tb_TinTucDanhMuc objects from the datasource by ID_TinTuc in the
		///		tb_TinTucSuKien table. Table tb_TinTucDanhMuc is related to table tb_TinTuc
		///		through the (M:N) relationship defined in the tb_TinTucSuKien table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <param name="iDTinTuc"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of TinTucDanhMuc objects.</returns>
		public abstract TList<TinTucDanhMuc> GetByIDTinTucFromTinTucSuKien(TransactionManager transactionManager,System.Guid iDTinTuc, int start, int pageLength, out int count);
		
		#endregion GetByIDTinTucFromTinTucSuKien
		
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, Indeco.G24.Entities.TinTucDanhMucKey key)
		{
			return Delete(transactionManager, key.IDTinTucDanhMuc);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="iDTinTucDanhMuc">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Guid iDTinTucDanhMuc)
		{
			return Delete(null, iDTinTucDanhMuc);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDTinTucDanhMuc">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Guid iDTinTucDanhMuc);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override Indeco.G24.Entities.TinTucDanhMuc Get(TransactionManager transactionManager, Indeco.G24.Entities.TinTucDanhMucKey key, int start, int pageLength)
		{
			return GetByIDTinTucDanhMuc(transactionManager, key.IDTinTucDanhMuc, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_tb_TinTucDanhMuc index.
		/// </summary>
		/// <param name="iDTinTucDanhMuc"></param>
		/// <returns>Returns an instance of the <see cref="Indeco.G24.Entities.TinTucDanhMuc"/> class.</returns>
		public Indeco.G24.Entities.TinTucDanhMuc GetByIDTinTucDanhMuc(System.Guid iDTinTucDanhMuc)
		{
			int count = -1;
			return GetByIDTinTucDanhMuc(null,iDTinTucDanhMuc, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tb_TinTucDanhMuc index.
		/// </summary>
		/// <param name="iDTinTucDanhMuc"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="Indeco.G24.Entities.TinTucDanhMuc"/> class.</returns>
		public Indeco.G24.Entities.TinTucDanhMuc GetByIDTinTucDanhMuc(System.Guid iDTinTucDanhMuc, int start, int pageLength)
		{
			int count = -1;
			return GetByIDTinTucDanhMuc(null, iDTinTucDanhMuc, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tb_TinTucDanhMuc index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDTinTucDanhMuc"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="Indeco.G24.Entities.TinTucDanhMuc"/> class.</returns>
		public Indeco.G24.Entities.TinTucDanhMuc GetByIDTinTucDanhMuc(TransactionManager transactionManager, System.Guid iDTinTucDanhMuc)
		{
			int count = -1;
			return GetByIDTinTucDanhMuc(transactionManager, iDTinTucDanhMuc, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tb_TinTucDanhMuc index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDTinTucDanhMuc"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="Indeco.G24.Entities.TinTucDanhMuc"/> class.</returns>
		public Indeco.G24.Entities.TinTucDanhMuc GetByIDTinTucDanhMuc(TransactionManager transactionManager, System.Guid iDTinTucDanhMuc, int start, int pageLength)
		{
			int count = -1;
			return GetByIDTinTucDanhMuc(transactionManager, iDTinTucDanhMuc, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tb_TinTucDanhMuc index.
		/// </summary>
		/// <param name="iDTinTucDanhMuc"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="Indeco.G24.Entities.TinTucDanhMuc"/> class.</returns>
		public Indeco.G24.Entities.TinTucDanhMuc GetByIDTinTucDanhMuc(System.Guid iDTinTucDanhMuc, int start, int pageLength, out int count)
		{
			return GetByIDTinTucDanhMuc(null, iDTinTucDanhMuc, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tb_TinTucDanhMuc index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDTinTucDanhMuc"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="Indeco.G24.Entities.TinTucDanhMuc"/> class.</returns>
		public abstract Indeco.G24.Entities.TinTucDanhMuc GetByIDTinTucDanhMuc(TransactionManager transactionManager, System.Guid iDTinTucDanhMuc, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a Indeco.G24.Entities.TList&lt;TinTucDanhMuc&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="Indeco.G24.Entities.TList&lt;TinTucDanhMuc&gt;"/></returns>
		public static Indeco.G24.Entities.TList<TinTucDanhMuc> Fill(IDataReader reader, Indeco.G24.Entities.TList<TinTucDanhMuc> rows, int start, int pageLength)
		{
		// advance to the starting row
		for (int i = 0; i < start; i++)
		{
			if (!reader.Read())
			return rows; // not enough rows, just return
		}
		for (int i = 0; i < pageLength; i++)
		{
			if (!reader.Read())
			break; // we are done
			string key = null;
			
			Indeco.G24.Entities.TinTucDanhMuc c = null;
			if (DataRepository.Provider.UseEntityFactory)
			{
			key = new System.Text.StringBuilder("TinTucDanhMuc")
			.Append("|").Append((reader.IsDBNull(((int)Indeco.G24.Entities.TinTucDanhMucColumn.IDTinTucDanhMuc - 1))?Guid.NewGuid():(System.Guid)reader[((int)Indeco.G24.Entities.TinTucDanhMucColumn.IDTinTucDanhMuc - 1)]).ToString()).ToString();
			c = EntityManager.LocateOrCreate<TinTucDanhMuc>(
			key.ToString(), // EntityTrackingKey
			"TinTucDanhMuc",  //Creational Type
			DataRepository.Provider.EntityCreationalFactoryType,  //Factory used to create entity
			DataRepository.Provider.EnableEntityTracking); // Track this entity?
			}
			else
			{
			c = new Indeco.G24.Entities.TinTucDanhMuc();
			}
			
			if (!DataRepository.Provider.EnableEntityTracking ||
			c.EntityState == EntityState.Added ||
			(DataRepository.Provider.EnableEntityTracking &&
			((DataRepository.Provider.CurrentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
			(DataRepository.Provider.CurrentLoadPolicy == LoadPolicy.DiscardChanges && (c.EntityState == EntityState.Unchanged ||
								c.EntityState == EntityState.Changed)))))
						{
			c.SuppressEntityEvents = true;
			c.IDTinTucDanhMuc = (System.Guid)reader["ID_TinTucDanhMuc"];
			c.OriginalIDTinTucDanhMuc = c.IDTinTucDanhMuc;
			c.IDTinTucDanhMucCha = (System.Guid)reader["ID_TinTucDanhMucCha"];
			c.Ten = (System.String)reader["Ten"];
			c.SoLienKet = (System.Byte)reader["SoLienKet"];
			c.ViTri = (System.Byte)reader["ViTri"];
			c.NhaCungCap = reader.IsDBNull(reader.GetOrdinal("NhaCungCap")) ? null : (System.String)reader["NhaCungCap"];
			c.TrangThai = (System.Boolean)reader["TrangThai"];
			c.ThoiDiemChinhSua = (System.DateTime)reader["ThoiDiemChinhSua"];
			c.ThoiDiemCapNhat = (System.DateTime)reader["ThoiDiemCapNhat"];
			c.EntityTrackingKey = key;
			c.AcceptChanges();
			c.SuppressEntityEvents = false;
			}
			rows.Add(c);
		}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="Indeco.G24.Entities.TinTucDanhMuc"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="Indeco.G24.Entities.TinTucDanhMuc"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, Indeco.G24.Entities.TinTucDanhMuc entity)
		{
			if (!reader.Read()) return;
			
			entity.IDTinTucDanhMuc = (System.Guid)reader["ID_TinTucDanhMuc"];
			entity.OriginalIDTinTucDanhMuc = (System.Guid)reader["ID_TinTucDanhMuc"];
			entity.IDTinTucDanhMucCha = (System.Guid)reader["ID_TinTucDanhMucCha"];
			entity.Ten = (System.String)reader["Ten"];
			entity.SoLienKet = (System.Byte)reader["SoLienKet"];
			entity.ViTri = (System.Byte)reader["ViTri"];
			entity.NhaCungCap = reader.IsDBNull(reader.GetOrdinal("NhaCungCap")) ? null : (System.String)reader["NhaCungCap"];
			entity.TrangThai = (System.Boolean)reader["TrangThai"];
			entity.ThoiDiemChinhSua = (System.DateTime)reader["ThoiDiemChinhSua"];
			entity.ThoiDiemCapNhat = (System.DateTime)reader["ThoiDiemCapNhat"];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="Indeco.G24.Entities.TinTucDanhMuc"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="Indeco.G24.Entities.TinTucDanhMuc"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, Indeco.G24.Entities.TinTucDanhMuc entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.IDTinTucDanhMuc = (System.Guid)dataRow["ID_TinTucDanhMuc"];
			entity.OriginalIDTinTucDanhMuc = (System.Guid)dataRow["ID_TinTucDanhMuc"];
			entity.IDTinTucDanhMucCha = (System.Guid)dataRow["ID_TinTucDanhMucCha"];
			entity.Ten = (System.String)dataRow["Ten"];
			entity.SoLienKet = (System.Byte)dataRow["SoLienKet"];
			entity.ViTri = (System.Byte)dataRow["ViTri"];
			entity.NhaCungCap = Convert.IsDBNull(dataRow["NhaCungCap"]) ? null : (System.String)dataRow["NhaCungCap"];
			entity.TrangThai = (System.Boolean)dataRow["TrangThai"];
			entity.ThoiDiemChinhSua = (System.DateTime)dataRow["ThoiDiemChinhSua"];
			entity.ThoiDiemCapNhat = (System.DateTime)dataRow["ThoiDiemCapNhat"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="Indeco.G24.Entities.TinTucDanhMuc"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">Indeco.G24.Entities.TinTucDanhMuc Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		internal override void DeepLoad(TransactionManager transactionManager, Indeco.G24.Entities.TinTucDanhMuc entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			// Deep load child collections  - Call GetByIDTinTucDanhMuc methods when available
			
			#region TinTucCollection_From_TinTucTieuDiem
			// RelationshipType.ManyToMany
			if (CanDeepLoad(entity, "List<TinTuc>|TinTucCollection_From_TinTucTieuDiem", deepLoadType, innerList))
			{
				entity.TinTucCollection_From_TinTucTieuDiem = DataRepository.TinTucProvider.GetByIDTinTucDanhMucFromTinTucTieuDiem(transactionManager, entity.IDTinTucDanhMuc);			 
		
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'TinTucCollection_From_TinTucTieuDiem' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.TinTucCollection_From_TinTucTieuDiem != null)
				{
					deepHandles.Add("TinTucCollection_From_TinTucTieuDiem",
						new KeyValuePair<Delegate, object>((DeepLoadHandle< TinTuc >) DataRepository.TinTucProvider.DeepLoad,
						new object[] { transactionManager, entity.TinTucCollection_From_TinTucTieuDiem, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion
			
			
			
			#region TinTucCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<TinTuc>|TinTucCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'TinTucCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.TinTucCollection = DataRepository.TinTucProvider.GetByIDTinTucDanhMuc(transactionManager, entity.IDTinTucDanhMuc);

				if (deep && entity.TinTucCollection.Count > 0)
				{
					deepHandles.Add("TinTucCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<TinTuc>) DataRepository.TinTucProvider.DeepLoad,
						new object[] { transactionManager, entity.TinTucCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region TinTucTieuDiemCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<TinTucTieuDiem>|TinTucTieuDiemCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'TinTucTieuDiemCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.TinTucTieuDiemCollection = DataRepository.TinTucTieuDiemProvider.GetByIDTinTucDanhMuc(transactionManager, entity.IDTinTucDanhMuc);

				if (deep && entity.TinTucTieuDiemCollection.Count > 0)
				{
					deepHandles.Add("TinTucTieuDiemCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<TinTucTieuDiem>) DataRepository.TinTucTieuDiemProvider.DeepLoad,
						new object[] { transactionManager, entity.TinTucTieuDiemCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region TinTucSuKienCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<TinTucSuKien>|TinTucSuKienCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'TinTucSuKienCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.TinTucSuKienCollection = DataRepository.TinTucSuKienProvider.GetByIDTinTucDanhMuc(transactionManager, entity.IDTinTucDanhMuc);

				if (deep && entity.TinTucSuKienCollection.Count > 0)
				{
					deepHandles.Add("TinTucSuKienCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<TinTucSuKien>) DataRepository.TinTucSuKienProvider.DeepLoad,
						new object[] { transactionManager, entity.TinTucSuKienCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region TinTucCollection_From_TinTucSuKien
			// RelationshipType.ManyToMany
			if (CanDeepLoad(entity, "List<TinTuc>|TinTucCollection_From_TinTucSuKien", deepLoadType, innerList))
			{
				entity.TinTucCollection_From_TinTucSuKien = DataRepository.TinTucProvider.GetByIDTinTucDanhMucFromTinTucSuKien(transactionManager, entity.IDTinTucDanhMuc);			 
		
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'TinTucCollection_From_TinTucSuKien' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.TinTucCollection_From_TinTucSuKien != null)
				{
					deepHandles.Add("TinTucCollection_From_TinTucSuKien",
						new KeyValuePair<Delegate, object>((DeepLoadHandle< TinTuc >) DataRepository.TinTucProvider.DeepLoad,
						new object[] { transactionManager, entity.TinTucCollection_From_TinTucSuKien, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion
			
			
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the Indeco.G24.Entities.TinTucDanhMuc object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">Indeco.G24.Entities.TinTucDanhMuc instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">Indeco.G24.Entities.TinTucDanhMuc Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		internal override bool DeepSave(TransactionManager transactionManager, Indeco.G24.Entities.TinTucDanhMuc entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<Delegate, object> deepHandles = new Dictionary<Delegate, object>();

			#region TinTucCollection_From_TinTucTieuDiem>
			if (CanDeepSave(entity.TinTucCollection_From_TinTucTieuDiem, "List<TinTuc>|TinTucCollection_From_TinTucTieuDiem", deepSaveType, innerList))
			{
				if (entity.TinTucCollection_From_TinTucTieuDiem.Count > 0 || entity.TinTucCollection_From_TinTucTieuDiem.DeletedItems.Count > 0)
				{
					DataRepository.TinTucProvider.Save(transactionManager, entity.TinTucCollection_From_TinTucTieuDiem); 
					deepHandles.Add(
						(DeepSaveHandle<TinTuc>) DataRepository.TinTucProvider.DeepSave,
						new object[] { transactionManager, entity.TinTucCollection_From_TinTucTieuDiem, deepSaveType, childTypes, innerList }
					);
				}
			}
			#endregion 

			#region TinTucCollection_From_TinTucSuKien>
			if (CanDeepSave(entity.TinTucCollection_From_TinTucSuKien, "List<TinTuc>|TinTucCollection_From_TinTucSuKien", deepSaveType, innerList))
			{
				if (entity.TinTucCollection_From_TinTucSuKien.Count > 0 || entity.TinTucCollection_From_TinTucSuKien.DeletedItems.Count > 0)
				{
					DataRepository.TinTucProvider.Save(transactionManager, entity.TinTucCollection_From_TinTucSuKien); 
					deepHandles.Add(
						(DeepSaveHandle<TinTuc>) DataRepository.TinTucProvider.DeepSave,
						new object[] { transactionManager, entity.TinTucCollection_From_TinTucSuKien, deepSaveType, childTypes, innerList }
					);
				}
			}
			#endregion 
	
			#region List<TinTuc>
				if (CanDeepSave(entity.TinTucCollection, "List<TinTuc>|TinTucCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(TinTuc child in entity.TinTucCollection)
					{
						if(child.IDTinTucDanhMucSource != null)
							child.IDTinTucDanhMuc = child.IDTinTucDanhMucSource.IDTinTucDanhMuc;
						else
							child.IDTinTucDanhMuc = entity.IDTinTucDanhMuc;

					}

					if (entity.TinTucCollection.Count > 0 || entity.TinTucCollection.DeletedItems.Count > 0)
					{
						DataRepository.TinTucProvider.Save(transactionManager, entity.TinTucCollection);
						
						deepHandles.Add(
							(DeepSaveHandle< TinTuc >) DataRepository.TinTucProvider.DeepSave,
							new object[] { transactionManager, entity.TinTucCollection, deepSaveType, childTypes, innerList }
						);
					}
				} 
			#endregion 
				
	
			#region List<TinTucTieuDiem>
				if (CanDeepSave(entity.TinTucTieuDiemCollection, "List<TinTucTieuDiem>|TinTucTieuDiemCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(TinTucTieuDiem child in entity.TinTucTieuDiemCollection)
					{
						if(child.IDTinTucDanhMucSource != null)
							child.IDTinTucDanhMuc = child.IDTinTucDanhMucSource.IDTinTucDanhMuc;
						else
							child.IDTinTucDanhMuc = entity.IDTinTucDanhMuc;

						//Handle right table of TinTucCollection_From_TinTucTieuDiem
						if(child.IDTinTucDanhMucSource != null)
						{
								child.IDTinTucDanhMuc = child.IDTinTucDanhMucSource.IDTinTucDanhMuc;

						}

						//Handle right table of TinTucCollection_From_TinTucTieuDiem
						if(child.IDTinTucSource != null)
						{
								child.IDTinTuc = child.IDTinTucSource.IDTinTuc;

						}

					}

					if (entity.TinTucTieuDiemCollection.Count > 0 || entity.TinTucTieuDiemCollection.DeletedItems.Count > 0)
					{
						DataRepository.TinTucTieuDiemProvider.Save(transactionManager, entity.TinTucTieuDiemCollection);
						
						deepHandles.Add(
							(DeepSaveHandle< TinTucTieuDiem >) DataRepository.TinTucTieuDiemProvider.DeepSave,
							new object[] { transactionManager, entity.TinTucTieuDiemCollection, deepSaveType, childTypes, innerList }
						);
					}
				} 
			#endregion 
				
	
			#region List<TinTucSuKien>
				if (CanDeepSave(entity.TinTucSuKienCollection, "List<TinTucSuKien>|TinTucSuKienCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(TinTucSuKien child in entity.TinTucSuKienCollection)
					{
						if(child.IDTinTucDanhMucSource != null)
							child.IDTinTucDanhMuc = child.IDTinTucDanhMucSource.IDTinTucDanhMuc;
						else
							child.IDTinTucDanhMuc = entity.IDTinTucDanhMuc;

						//Handle right table of TinTucCollection_From_TinTucSuKien
						if(child.IDTinTucDanhMucSource != null)
						{
								child.IDTinTucDanhMuc = child.IDTinTucDanhMucSource.IDTinTucDanhMuc;

						}

						//Handle right table of TinTucCollection_From_TinTucSuKien
						if(child.IDTinTucSource != null)
						{
								child.IDTinTuc = child.IDTinTucSource.IDTinTuc;

						}

					}

					if (entity.TinTucSuKienCollection.Count > 0 || entity.TinTucSuKienCollection.DeletedItems.Count > 0)
					{
						DataRepository.TinTucSuKienProvider.Save(transactionManager, entity.TinTucSuKienCollection);
						
						deepHandles.Add(
							(DeepSaveHandle< TinTucSuKien >) DataRepository.TinTucSuKienProvider.DeepSave,
							new object[] { transactionManager, entity.TinTucSuKienCollection, deepSaveType, childTypes, innerList }
						);
					}
				} 
			#endregion 
				
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region TinTucDanhMucChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>Indeco.G24.Entities.TinTucDanhMuc</c>
	///</summary>
	public enum TinTucDanhMucChildEntityTypes
	{

		///<summary>
		/// Collection of <c>TinTucDanhMuc</c> as ManyToMany for TinTucCollection_From_TinTucTieuDiem
		///</summary>
		[ChildEntityType(typeof(TList<TinTuc>))]
		TinTucCollection_From_TinTucTieuDiem,

		///<summary>
		/// Collection of <c>TinTucDanhMuc</c> as OneToMany for TinTucCollection
		///</summary>
		[ChildEntityType(typeof(TList<TinTuc>))]
		TinTucCollection,

		///<summary>
		/// Collection of <c>TinTucDanhMuc</c> as OneToMany for TinTucTieuDiemCollection
		///</summary>
		[ChildEntityType(typeof(TList<TinTucTieuDiem>))]
		TinTucTieuDiemCollection,

		///<summary>
		/// Collection of <c>TinTucDanhMuc</c> as OneToMany for TinTucSuKienCollection
		///</summary>
		[ChildEntityType(typeof(TList<TinTucSuKien>))]
		TinTucSuKienCollection,

		///<summary>
		/// Collection of <c>TinTucDanhMuc</c> as ManyToMany for TinTucCollection_From_TinTucSuKien
		///</summary>
		[ChildEntityType(typeof(TList<TinTuc>))]
		TinTucCollection_From_TinTucSuKien,
	}
	
	#endregion TinTucDanhMucChildEntityTypes
	
	#region TinTucDanhMucFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;TinTucDanhMucColumn&gt;"/> class
	/// that is used exclusively with a <see cref="TinTucDanhMuc"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class TinTucDanhMucFilterBuilder : SqlFilterBuilder<TinTucDanhMucColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the TinTucDanhMucFilterBuilder class.
		/// </summary>
		public TinTucDanhMucFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the TinTucDanhMucFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public TinTucDanhMucFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the TinTucDanhMucFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public TinTucDanhMucFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion TinTucDanhMucFilterBuilder
	
	#region TinTucDanhMucParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;TinTucDanhMucColumn&gt;"/> class
	/// that is used exclusively with a <see cref="TinTucDanhMuc"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class TinTucDanhMucParameterBuilder : ParameterizedSqlFilterBuilder<TinTucDanhMucColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the TinTucDanhMucParameterBuilder class.
		/// </summary>
		public TinTucDanhMucParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the TinTucDanhMucParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public TinTucDanhMucParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the TinTucDanhMucParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public TinTucDanhMucParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion TinTucDanhMucParameterBuilder
} // end namespace
